namespace TomatoBreak.Web
{
    using System;
    using System.ComponentModel.DataAnnotations;

    using DomainObjects;

    public class TaskModel
    {
        public TaskModel()
        {
            Planned = true;
        }

        [Required(ErrorMessageResourceName = "TaskNameRequired", ErrorMessageResourceType = typeof(ModelValidationMessages))]
        [StringLength(256, ErrorMessageResourceName = "TaskNameLength", ErrorMessageResourceType = typeof(ModelValidationMessages))]
        public string Name { get; set; }

        public bool Planned { get; set; }

        [DataType(DataType.MultilineText)]
        public string Notes { get; set; }

        public int? Estimation { get; set; }

        [DataType(DataType.Date)]
        public DateTime CreatedAt { get; set; }

        [DataType(DataType.Date)]
        public DateTime? DueAt { get; set; }

        public Task Create(User user)
        {
            var task = new Task(user, Name, CreatedAt);

            CopyTo(task);

            return task;
        }

        public void CopyTo(Task task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }

            task.Name = Name;
            task.Planned = Planned;
            task.Notes = Notes;
            task.Estimation = Estimation;
            task.DueAt = DueAt;
        }
    }
}